package com.study.mybatis.session;

import com.study.mybatis.config.Confingurtion;
import com.study.mybatis.exection.Exection;
import com.study.mybatis.proxy.MapperProxy;

import java.lang.reflect.Proxy;

public class SqlSession {

    private Confingurtion confingurtion;
    private Exection exection;

    public SqlSession(){
        this.exection = new Exection();
    }

    public <T> T getMapper(Class<T> clazz){
        return (T)Proxy.newProxyInstance(clazz.getClassLoader(),
                new Class[]{clazz},new MapperProxy(this));
    }

    public Object selectOne(String statementId, Object paramater){
        String sql = Confingurtion.sqlMappings.getString(statementId);
        if(null != sql && !"".equals(sql)){
            return exection.query(sql,paramater);
        }
        return null;
    }

    public Confingurtion getConfingurtion() {
        return confingurtion;
    }

    public void setConfingurtion(Confingurtion confingurtion) {
        this.confingurtion = confingurtion;
    }

    public Exection getExection() {
        return exection;
    }

    public void setExection(Exection exection) {
        this.exection = exection;
    }
}
